<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<script type="text/javascript" src="./baidu_files/jquery-2.1.4.min.js"></script>
	<style type="text/css">
		body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
		#allmap{height:100%;width:100%;}
		#r-result{width:100%;}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=s829ZA0Zg0QyMCy1F1FxQdV7hTI5Z2qU"></script>
	<title></title>
</head>
<body>
	<div id="allmap"></div>
	<div id="r-result">
		<input type="button" onclick="add_overlay();" value="添加覆盖物" />
		<input type="button" onclick="remove_overlay();" value="删除覆盖物" />
	</div>
</body>
</html>
<script type="text/javascript">
	// 百度地图API功能
	

    var opts = {
				width : 250,     // 信息窗口宽度
				height: 80,     // 信息窗口高度
				title : "信息窗口" , // 信息窗口标题
				enableMessage:true//设置允许信息窗发送短息
			   };

			   var map = new BMap.Map("allmap");  
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 4);  
    map.enableScrollWheelZoom();  
    var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
	var top_left_navigation = new BMap.NavigationControl();
    map.addControl(top_left_control);        
		map.addControl(top_left_navigation);     
    var MAX = 10;  
    var markers = [];  
    var markerClusterer = null;  
    var adds= [];
    var index = 0;
    var myGeo = new BMap.Geocoder(); 
	var zoom = -1;

	var posturl = "http://www.myliferv.com/motorhome-api/api/device/getLocation";
    // var url = "http://www.myliferv.com/motorhome-api/api/device/getLocation";
    var Table = document.getElementById("table-3");   //取得自定义的表对象 
	var deviceNumber = ""; 
	var myurl=GetQueryString("deviceNumber");
if(myurl !=null && myurl.toString().length>1)
{
    deviceNumber = myurl;
}
	setInterval('refreshQuery()',10000);   
	refreshQuery();
	function refreshQuery(){  
    $.post(posturl, {"deviceNumber":deviceNumber}, function (data) {

        // data = '{"ret":0,"msg":"成功","data":{"TotalCount":27,"CurrentCount":27,"DeviceList":[{"DeviceId":173808,"DeviceNumber":"881098310264714","DeviceState":1,"ActiveState":1,"Time":"2018/4/23 16:07:33","Lng":120.16159737,"Lat":30.27862284,"Speed":13.1,"Location":"浙江省杭州市下城区环城西路104号[杭州市人民政府-大楼南96米]"},{"DeviceId":174216,"DeviceNumber":"881098310265132","DeviceState":1,"ActiveState":1,"Time":"2018/4/8 8:56:43","Lng":103.96856887,"Lat":30.56997986,"Speed":0.0,"Location":"四川省成都市双流县机场东三路[随园花园餐厅附近21米]"},{"DeviceId":177336,"DeviceNumber":"881098310265290","DeviceState":1,"ActiveState":1,"Time":"2018/4/15 18:54:31","Lng":120.65859249,"Lat":28.0238351,"Speed":0.9,"Location":"浙江省温州市鹿城区三官殿巷143号[三官殿巷147号院附近47米]"},{"DeviceId":177419,"DeviceNumber":"881098310265323","DeviceState":1,"ActiveState":1,"Time":"2018/4/13 15:30:48","Lng":118.77381859,"Lat":32.03140889,"Speed":5.7,"Location":"江苏省南京市建邺区长虹路90号[长虹大市场东61米]"},{"DeviceId":177426,"DeviceNumber":"881098310265328","DeviceState":1,"ActiveState":1,"Time":"2018/4/23 16:08:09","Lng":118.60205475,"Lat":31.21668297,"Speed":14.8,"Location":"安徽省芜湖市芜湖县新竹服务区[新竹服务区北85米]"},{"DeviceId":177660,"DeviceNumber":"881098310265552","DeviceState":1,"ActiveState":1,"Time":"2018/4/23 15:50:13","Lng":104.17841524,"Lat":30.65660764,"Speed":0.1,"Location":"四川省成都市龙泉驿区蜀王大道北段[食林村大酒店南95米]"},{"DeviceId":185516,"DeviceNumber":"882098310278870","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:34:34","Lng":118.83220627,"Lat":31.84828956,"Speed":0.3,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北302米]"},{"DeviceId":185412,"DeviceNumber":"882098310279076","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:35:45","Lng":118.83215637,"Lat":31.84827419,"Speed":0.4,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北305米]"},{"DeviceId":185787,"DeviceNumber":"882098310279269","DeviceState":1,"ActiveState":1,"Time":"2018/4/20 17:01:35","Lng":118.59016362,"Lat":32.14488483,"Speed":0.1,"Location":"江苏省南京市浦口区[薛家营南227米]"},{"DeviceId":185927,"DeviceNumber":"882098310279349","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:31:57","Lng":118.83218947,"Lat":31.84840295,"Speed":0.4,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北318米]"},{"DeviceId":185962,"DeviceNumber":"882098310279381","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:37:12","Lng":118.83230343,"Lat":31.8482025,"Speed":0.0,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北280米]"},{"DeviceId":185820,"DeviceNumber":"882098310279414","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:36:32","Lng":118.83220627,"Lat":31.84838789,"Speed":0.6,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北302米]"},{"DeviceId":185848,"DeviceNumber":"882098310279427","DeviceState":1,"ActiveState":1,"Time":"2018/4/23 10:08:51","Lng":116.86250479,"Lat":32.60550492,"Speed":0.0,"Location":"安徽省淮南市谢家集区平山路[谢三村南区-东北门西南74米]"},{"DeviceId":186247,"DeviceNumber":"882098310279449","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:37:56","Lng":118.83199442,"Lat":31.84803362,"Speed":0.5,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄西北289米]"},{"DeviceId":185923,"DeviceNumber":"882098310279458","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:34:26","Lng":118.83228656,"Lat":31.84853905,"Speed":1.6,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北324米]"},{"DeviceId":186020,"DeviceNumber":"882098310279502","DeviceState":1,"ActiveState":1,"Time":"2018/4/21 16:11:34","Lng":118.764653,"Lat":31.97689075,"Speed":1.8,"Location":"江苏省南京市雨花台区宁双路7号[凤翔新城内]"},{"DeviceId":186239,"DeviceNumber":"882098310279504","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:36:28","Lng":118.8319439,"Lat":31.84812812,"Speed":2.0,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北314米]"},{"DeviceId":186024,"DeviceNumber":"882098310279607","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:36:34","Lng":118.8320593,"Lat":31.84808556,"Speed":2.0,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北300米]"},{"DeviceId":186067,"DeviceNumber":"882098310279623","DeviceState":1,"ActiveState":1,"Time":"2018/4/19 18:41:24","Lng":118.37811079,"Lat":31.37414891,"Speed":0.0,"Location":"安徽省芜湖市镜湖区天门山西路6号[皇廷宾馆南79米]"},{"DeviceId":186084,"DeviceNumber":"882098310279631","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:33:00","Lng":118.83217284,"Lat":31.84839652,"Speed":1.4,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北337米]"},{"DeviceId":186092,"DeviceNumber":"882098310279635","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:37:38","Lng":118.83217305,"Lat":31.84819178,"Speed":0.2,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北273米]"},{"DeviceId":186182,"DeviceNumber":"882098310279677","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:34:32","Lng":118.83225464,"Lat":31.84841502,"Speed":0.5,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北334米]"},{"DeviceId":186189,"DeviceNumber":"882098310279683","DeviceState":1,"ActiveState":0,"Time":"2018/3/10 11:55:53","Lng":118.77388337,"Lat":32.03117403,"Speed":0.5,"Location":"江苏省南京市建邺区长虹路96号[长虹大市场东南76米]"},{"DeviceId":186537,"DeviceNumber":"882098310279701","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:35:14","Lng":118.8323369,"Lat":31.84822123,"Speed":2.2,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北285米]"},{"DeviceId":186245,"DeviceNumber":"882098310279730","DeviceState":1,"ActiveState":0,"Time":"2018/1/31 11:38:54","Lng":118.8320743,"Lat":31.84823889,"Speed":1.1,"Location":"江苏省南京市江宁区X003(正方中路)[前晋家庄北300米]"},{"DeviceId":186234,"DeviceNumber":"882098310279757","DeviceState":1,"ActiveState":1,"Time":"2018/4/23 8:43:46","Lng":118.74377444,"Lat":31.98849005,"Speed":0.1,"Location":"江苏省南京市建邺区广聚路[新城科技园科技创新综合体东北88米]"},{"DeviceId":73740,"DeviceNumber":"V7098410169551","DeviceState":0,"ActiveState":0,"Time":"2017/2/18 23:52:40","Lng":118.82940092,"Lat":31.87762199,"Speed":0.0,"Location":"江苏省南京市江宁区秣周东路"}]}}';
        var json_data = data.data;
        var ret = data.ret;
		if(ret == 0)
		{
   
            
             var DeviceNumber = deviceNumber;
			 var DeviceID = json_data.DeviceId;
             var Time = json_data.Time;
             var Lng = json_data.Lng;
             var Lat = json_data.Lat;
             var Location1 = json_data.Location;
 
            var status = "";
           

        

             var sContent =
            "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>车辆定位信息</h4>" + 
            "<p style='margin:0;line-height:1.5;font-size:13px;'>设备编号："+DeviceNumber+"</p>" + 
            "<p style='margin:0;line-height:1.5;font-size:13px;'>车号:"+DeviceID+"</p>" + 
            "<p style='margin:0;line-height:1.5;font-size:13px;'>时间:"+Time+"</p>" + 
                "<p style='margin:0;line-height:1.5;font-size:13px;'>地点:"+Location1+"</p>" + 
            "</div>";
            var pt = new BMap.Point(Lng, Lat); 
            // var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
            var marker = new BMap.Marker(pt); 
            var pp=Lng+","+Lat;
            var marker1 = new BMap.Marker(new BMap.Point(pp,Location1)); 
            var pt = new BMap.Point(Lng, Lat); 

			if(zoom==-1)
			{
            map.centerAndZoom(pt, 18); 
			zoom = 18;
			}else{
				zoom= map.getZoom();
				map.centerAndZoom(pt, zoom); 
			} 
            // marker.addEventListener("click", function(){          
            // map.openInfoWindow(infoWindow,pt);
           
	        // });
            map.addOverlay(marker); 
            
            addClickHandler(sContent,marker);
            markers.push(marker);  
        }
 
        add_overlay();
    })
} 
 
    function add_overlay(){  
        //最简单的用法，生成一个marker数组，然后调用markerClusterer类即可。  
        markerClusterer = new BMapLib.MarkerClusterer(map, {markers:markers});  
        // alert(1);
    }  
    function addClickHandler(content,markerbak){
		markerbak.addEventListener("click",function(e){
			openInfo(content,e)}
		);
	}
	function openInfo(content,e){
		var p = e.target;
		var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
		var infoWindow = new BMap.InfoWindow(content);  // 创建信息窗口对象 
		map.openInfoWindow(infoWindow,point); //开启信息窗口
	}

	function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
</script>

